/*
 * Copyright 2020-2021 redragon.dongbin
 *
 * This file is part of redragon-erp/赤龙ERP.

 * redragon-erp/赤龙ERP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.

 * redragon-erp/赤龙ERP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with redragon-erp/赤龙ERP.  If not, see <https://www.gnu.org/licenses/>.
 */
package com.erp.prod.mrp.dao.model;

import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
@Data
@Entity
@Table(name="prod_mrp_line", schema="erp")
@DynamicInsert(true)
@DynamicUpdate(true)
public class ProdMrpLine implements java.io.Serializable {

    //serialVersionUID
    private static final long serialVersionUID = 1L;

    //Constructors
    public ProdMrpLine() {
    }
    
    //Fields
    
    //主键
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "mrp_line_id", unique = true, nullable = false)
    private Integer mrpLineId;

    //mrp行编码
    @Column(name = "mrp_line_code", unique = true, nullable = false, length = 45)
    private String mrpLineCode;

    //mrp头编码
    @Column(name = "mrp_head_code", unique = false, nullable = false, length = 45)
    private String mrpHeadCode;

    //mps行编码
    //@NotBlank(message="主生产计划行编码不能为空")
    @Column(name = "mps_line_code", unique = false, nullable = true, length = 45)
    private String mpsLineCode;

    //物料编码
    @NotBlank(message="物料编码不能为空")
    @Column(name = "material_code", unique = false, nullable = false, length = 45)
    private String materialCode;

    //计划数量
    @NotNull(message="计划数量不能为空")
    @Column(name = "plan_quantity", unique = false, nullable = false)
    private BigDecimal planQuantity;

    //物料bom属性（自制MAKE、采购PO、委外ENTRUST）
    @NotBlank(message="物料属性不能为空")
    @Column(name = "bom_property", unique = false, nullable = false, length = 45)
    private String bomProperty;

    //计划开始日期
    @NotNull(message="计划开始日期不能为空")
    @Column(name = "plan_start_date", unique = false, nullable = false)
    private Date planStartDate;

    //计划结束日期
    @NotNull(message="计划结束日期不能为空")
    @Column(name = "plan_end_date", unique = false, nullable = false)
    private Date planEndDate;

    //摘要
    @Column(name = "memo", unique = false, nullable = true, length = 200)
    private String memo;

    //版本
    @Column(name = "version", unique = false, nullable = false)
    private Integer version;

    //状态
    @Column(name = "status", unique = false, nullable = false, length = 10)
    private String status;

    //创建时间
    @Column(name = "created_date", unique = false, nullable = false)
    private Date createdDate;

    //创建人
    @Column(name = "created_by", unique = false, nullable = false, length = 45)
    private String createdBy;

    //最后修改时间
    @Column(name = "last_updated_date", unique = false, nullable = true)
    private Date lastUpdatedDate;

    //最后修改人
    @Column(name = "last_updated_by", unique = false, nullable = true, length = 45)
    private String lastUpdatedBy;

    //组织机构
    @Column(name = "org_code", unique = false, nullable = false, length = 10)
    private String orgCode;

    //用于显示的字段
    @Transient
    private String materialName;
    @Transient
    private String materialStandard;
    @Transient
    private String materialUnit;
    @Transient
    private BigDecimal needQuantity;
    @Transient
    private BigDecimal stockQuantity;
    @Transient
    private BigDecimal willInputQuantity;
    @Transient
    private String poaLineCode;
    @Transient
    private String wipHeadCode;


    public BigDecimal getNeedQuantity() {
        return this.getPlanQuantity().subtract(this.getStockQuantity()).subtract(this.getWillInputQuantity());
    }

    
}